package main

import "fmt"

func changIntValue(x int) {
	x = 100
}

func changStrValue(x string) {
	x = "new value "
}

//修改指针地址的值
func changIntPointValue(x *int) {
	*x = 100
}

//内部的数组实际是指针的副本传递
func changeSlice(strSlice []string) {
	strSlice[0] = "new index 1 value"
}

func changMap(map1 map[string]string) {
	map1["index1"] = "new index 1 Value"
}

type Student struct {
	name string
	age  int
}

func changeStruct(st *Student) {
	st.age = st.age + 1
}

func main() {

	x := 99
	fmt.Println("执行 changIntValue 前 x = ", x)
	changIntValue(x)
	fmt.Println("执行 changIntValue 后 x = ", x)
	fmt.Println("-----------------------------")

	y := "old value"
	fmt.Println("执行 changStrValue 前 y = ", y)
	changStrValue(y)
	fmt.Println("执行 changStrValue 后 y = ", y)
	fmt.Println("-----------------------------")

	fmt.Println("执行 changIntPointValue 前 x = ", x)
	changIntPointValue(&x)
	fmt.Println("执行 changIntPointValue 后 x = ", x)
	fmt.Println("-----------------------------")

	var strSlice = make([]string, 1)
	strSlice[0] = "index 1 value "
	fmt.Println("执行 changeSlice 前 strSlice = ", strSlice)
	changeSlice(strSlice)
	fmt.Println("执行 changeSlice 后 strSlice = ", strSlice)
	fmt.Println("-----------------------------")

	var map1 = make(map[string]string, 1)
	map1["index1"] = "index 1 value "
	fmt.Println("执行 changMap 前 map1 = ", map1)
	changMap(map1)
	fmt.Println("执行 changMap 后 map1 = ", map1)
	fmt.Println("-----------------------------")

	st1 := Student{name: "zhangsan", age: 12}
	fmt.Println("执行 changeStruct 前 st1 = ", st1)
	changeStruct(&st1)
	fmt.Println("执行 changeStruct 后 st1 = ", st1)
	fmt.Println("-----------------------------")
}
